package com.example.app2024.phonenum;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.app2024.R;

import java.util.List;

public class PhoneNumActivity extends AppCompatActivity
{
      private ListView lv;
      private MyAdapter adapter;
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
            super.onCreate(savedInstanceState);
            EdgeToEdge.enable(this);
            setContentView(R.layout.activity_phone_num);
            ViewCompat.setOnApplyWindowInsetsListener(
                    findViewById(R.id.main), (v, insets) -> {
                          Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                          v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
                          return insets;
                    });

            int back = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_CONTACTS);
            if (back != PackageManager.PERMISSION_GRANTED)
            {
                  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, 10000);
            }

            GetNumber.getNumber(this);
            if (GetNumber.lists.size() >0)
            {
                  TextView textView =  findViewById(R.id.tv_showdebug);
                  textView.setText( GetNumber.lists.get(0).getNumber()  + "   "  + GetNumber.lists.get(0).getName());
                  adapter = new MyAdapter(GetNumber.lists, this);
                  lv = findViewById(R.id.lv);
                  lv.setAdapter(adapter);
            }
      }


}